<?php
namespace Topxia\Service\Kuke\Impl;

use Topxia\Common\ArrayToolkit;
use Topxia\Service\Common\BaseService;
use Topxia\Service\Kuke\BaomingService;

class BaomingServiceImpl extends BaseService implements BaomingService
{
    public function getBaomingList()
    {
        return $this->getBaomingDao()->getBaomingList();
    }
	
    public function checkShenfenzheng($sfz)
    {
        return $this->getBaomingDao()->checkShenfenzheng($sfz);
    }
	
    public function save($fields)
    {
        return $this->getBaomingDao()->save($fields);
    }
	public function searchBaoming(array $conditions, array $orderBy, $start, $limit)
	{
		$users = $this->getBaomingDao()->searchBaoming($conditions, $orderBy, $start, $limit);
		return BaomingSerialize::unserializes($users);
	}

	public function searchBaomingCount(array $conditions)
	{
		return $this->getBaomingDao()->searchBaomingCount($conditions);
	}

    protected function getBaomingDao()
    {
        return $this->createDao('Kuke.BaomingDao');
    }
}

class BaomingSerialize
{
    public static function serialize(array $baoming)
    {
		foreach($baoming as $k =>$v){
			$baoming[$k]=htmlspecialchars($baoming[$k]);
		}
        return $baoming;
    }

    public static function unserialize(array $baoming = null)
    {
        if (empty($baoming)) {
            return null;
        }
		
		// foreach($baoming as $k =>$v){
			// $baoming[$k]=htmlspecialchars_decode()($baoming[$k]);
		// }

        return $baoming;
    }

    public static function unserializes(array $users)
    {
        return array_map(function ($baoming) {
            return BaomingSerialize::unserialize($baoming);
        }, $users);
    }
}
